package com.baizhi.util;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/4/8.
 */
public class getmethodUtil {
    private  Class clazz;

    public getmethodUtil(Class calzz) {
        this.clazz=calzz;
    }

    public static List<Method>  getMethod(Class clazz) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException {
//        获取属性对象那个数组
        Field[] clazzFields = clazz.getDeclaredFields();
        List getMethords = new ArrayList();
        //对属性集合循环处理成get方法
        for (int i = 0; i < clazzFields.length; i++) {
            //        3.获取属性名
            String guruFieldName = clazzFields[i].getName();
//            4.拼接出来get方法名
            String getMethodName = "get"+guruFieldName.substring(0,1).toUpperCase()+guruFieldName.substring(1);
            Method getMethod = clazz.getDeclaredMethod(getMethodName, null);
            getMethords.add(i,getMethod);
            System.out.println(getMethod);
        }

        return getMethords;

    }
}
